import pandas as pd
from datetime import datetime

# 定义2025年全年的日期
start_date = '2025-01-01'
end_date = '2025-12-31'
date_range = pd.date_range(start=start_date, end=end_date)

# 定义2025年股市休市的节假日
holidays = [
    '2025-01-01',  # 元旦
    '2025-01-28', '2025-01-29', '2025-01-30', '2025-01-31', '2025-02-01', '2025-02-02', '2025-02-03', '2025-02-04',
    # 春节
    '2025-04-04', '2025-04-05', '2025-04-06',  # 清明节
    '2025-05-01', '2025-05-02', '2025-05-03', '2025-05-04', '2025-05-05',  # 劳动节
    '2025-06-01', '2025-06-02', '2025-06-03',  # 端午节
    '2025-10-01', '2025-10-02', '2025-10-03', '2025-10-04', '2025-10-05', '2025-10-06', '2025-10-07', '2025-10-08',
    # 国庆节、中秋节
]

# 过滤出交易日
# trading_days = [date.strftime('%Y-%m-%d') for date in date_range if
#                 date.strftime('%Y-%m-%d') not in holidays and date.weekday() < 5]

# 过滤出交易日并添加“星期”列（中文）
trading_days = []
for date in date_range:
    if date.strftime('%Y-%m-%d') not in holidays and date.weekday() < 5:
        # 将英文星期转换为中文
        weekday_mapping = {
            0: '星期一',
            1: '星期二',
            2: '星期三',
            3: '星期四',
            4: '星期五',
        }
        trading_day = {
            'Trading Day': date.strftime('%Y-%m-%d'),
            'Week Day': weekday_mapping.get(date.weekday(), '未知')
        }
        trading_days.append(trading_day)

length = len(trading_days)

# 输出本年度的股市开盘日期
print(f'2025年股市开盘日期({length}))：')

for day in trading_days:
    print(day)

# 创建DataFrame
df = pd.DataFrame(trading_days)
# 保存到Excel文件
excel_file = '2025_trading_days.xlsx'
df.to_excel(excel_file, index=False)